package javasec.contempt;

import javasec.contempt.actions.*;
import javasec.contempt.data.SeedConnector;

import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;


/**
 * An action bar advisor is responsible for creating, adding, and disposing of
 * the actions added to a workbench window. Each window will be populated with
 * new actions.
 */
public class ApplicationActionBarAdvisor extends ActionBarAdvisor
{
	// Actions - important to allocate these only in makeActions, and then use
	// them
	// in the fill methods. This ensures that the actions aren't recreated
	// when fillActionBars is called with FILL_PROXY.
	private IWorkbenchAction keyManagerAction;
	private IWorkbenchAction exitAction;
	private IWorkbenchAction localNetworkEditorAction;
	
	private IWorkbenchAction databaseViewAction;
	private IWorkbenchAction visualsViewAction;
	private IWorkbenchAction seedViewAction;
	private IWorkbenchAction consoleViewAction;
	
	private IWorkbenchAction startSeedAction;
	private IWorkbenchAction connectLocalAction;
	private IWorkbenchAction connectRemoteAction;
	private IWorkbenchAction disconnectAction;
	
	private IWorkbenchAction updateAction;
	
	
	public ApplicationActionBarAdvisor(IActionBarConfigurer configurer)
	{
		super(configurer);
	}

	protected void makeActions(final IWorkbenchWindow window)
	{
		// Creates the actions and registers them.
		// Registering is needed to ensure that key bindings work.
		// The corresponding commands keybindings are defined in the plugin.xml
		// file.
		// Registering also provides automatic disposal of the actions when
		// the window is closed.

		// file actions
		keyManagerAction =new KeyManagerAction(window);
		exitAction = ActionFactory.QUIT.create(window);
		
		// view actions
		seedViewAction = new ConnectionsViewAction(window);
		databaseViewAction = new AssetsViewAction(window);
		visualsViewAction = new VisualsViewAction(window);
		consoleViewAction = new ConsoleViewAction(window);

		// server actions
		startSeedAction = new StartSeedAction(window);
		
		updateAction = ActionFactory.PREFERENCES.create(window);
		register(updateAction);
		
		//register(exitAction);
		//register(localNetworkEditorAction);
		// do I need to register these?
		
		// TODO there has to be a better way..
		// window is needed to open/close the views from the connection manager
		SeedConnector.window=window;
	}

	protected void fillMenuBar(IMenuManager menuBar)
	{
		MenuManager fileMenu = new MenuManager("&File",IWorkbenchActionConstants.M_FILE);
		MenuManager viewMenu = new MenuManager("&View",IWorkbenchActionConstants.M_FILE);
		MenuManager seedMenu = new MenuManager("&Seed",IWorkbenchActionConstants.M_FILE);
		MenuManager updateMenu = new MenuManager("&Update",IWorkbenchActionConstants.M_HELP);
		
		
		menuBar.add(fileMenu);
		fileMenu.add(keyManagerAction);
		fileMenu.add(exitAction);
		
		menuBar.add(viewMenu);
		viewMenu.add(seedViewAction);
		viewMenu.add(databaseViewAction);
		viewMenu.add(visualsViewAction);
		viewMenu.add(consoleViewAction);
		
		menuBar.add(seedMenu);
		seedMenu.add(startSeedAction);;
		//seedMenu.add(connectLocalAction);
		//seedMenu.add(connectRemoteAction);
		//seedMenu.add(disconnectAction);
		
		
        menuBar.add(updateMenu);
        updateMenu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
        updateMenu.add(new Separator());
        updateMenu.add(updateAction);

	}
}
